Using Git with rstudio-pubs-static
-
Before you can use git to keep track of your changes to your R project, you need to tell the git program (which keeps snapshots of your changes) who you are. To do this, execute the following commands in the command line:
$ git config --global user.email "you@example.com"
$ git config --global user.name "Your Name"
-
Go back to RStudio. Under 'Tools' select 'Version Control' then 'project setup'.
-
Under 'Version control system' select the 'Git' tab.
You now have a new option in the pane at top right, beside 'Environment' and 'History': 'git'.
-
Click on 'Git'.
The panel now displays all of the files created in this project folder.
-
Tick off the files you want to commit.
-
Click on the 'Commit' button.
A new window opens called 'RStudio: Review Changes'. This window shows you a preview of the text of each file, in green where material has been added, red where material has been deleted (these are the 'difs').
-
Add a commit message into the top right 'commit message' box.
You've now made a local commit to your git repository! If things go horribly wrong, you can roll back the changes. Now, let's setup your GitHub repo for this.
-
Go to your GitHub account.
-
Make a new repository; initialize it with a readme.md
-
Back in RStudio, click on the 'more' gearwheel on the Git tab.
-
Select shell (you could do this from the command line too, when you're in your project folder). This will open up a box into which you can type commands; we're going to tell git the location of our remote repository, add that info into the config, and do two pulls.
-
Open shell and execute the following commands:
$ git remote add origin https://github.com/YOUR-ACCOUNT/YOUR-REPO.git $ git config remote.origin.url https://github.com/YOUR-ACCOUNT/YOUR-REPO.git $ git pull -u origin master
And you now can push your changes to your remote repository whenever you make a new commit. There is a variation of markdown called RMarkdown that enables you to embed working R code into a document, and then 'knit' it into HTML or slide shows or PDFs. When you push those to a GitHub repo, you are now making data publications! The official R Markdown information can be found on the RStudio website.